<template>
  <div class="login-wrap">
    <div class="left-context">
      <img
        src="../assets/img/undraw_login_re_4vu2_1.png"
        alt=""
        class="login-img"
      />
    </div>
    <div class="right-context">
      <div class="context-text">欢迎登录创思设备管理系统</div>
      <div class="context-login">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm">
          <!-- 邮箱 -->
          邮箱
          <el-form-item prop="email">
            <el-input
              v-model="ruleForm.email"
              style="margin-top: 5px"
            ></el-input>
          </el-form-item>
          <!-- 密码 -->
          密码
          <el-form-item prop="password">
            <el-input
              type="password"
              v-model="ruleForm.password"
              style="margin-top: 5px"
            >
              <i
                slot="suffix"
                :class="[flag ? 'el-icon-view' : 'el-icon-minus']"
                style="margin-top: 8px; font-size: 18px"
                autocomplete="auto"
                @click="flag = !flag"
              />
            </el-input>
          </el-form-item>

          <el-checkbox v-model="ruleForm.checked">记住我</el-checkbox>
          <el-button class="forget-pwd" type="text" @click="resetpwdForm"
            >忘记密码？</el-button
          >

          <el-form-item style="width: 100%">
            <el-button
              size="medium"
              type="primary"
              class="submit-btn"
              @click="submitForm"
              >登录</el-button
            >
          </el-form-item>
        </el-form>
      </div>
      <div class="jump-register">
        你还没有账号？
        <el-button type="text" @click="registerForm">注册账号？</el-button>
        <!-- 作为测试 -->
        <!-- <el-button
          type="text"
          @click="userinformationForm"
          >用户完善</el-button
        > -->
        <!-- <el-button
          type="text"
          @click="indexForm"
          >用户完善</el-button
        > -->
      </div>
    </div>
  </div>
</template>
<script>
import { mixin } from "../mixins/index";
import { getLoginStatus } from "../api/index";
export default {
  mixins: [mixin],
  data: function () {
    return {
      flag: false,
      ruleForm: {
        email: "",
        password: "",
        checked: false,
      },
      rules: {
        email: [{ required: true, message: "请输入邮箱", trigger: "blur" }],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  methods: {
    submitForm() {
      let params = new URLSearchParams();
      params.append("email", this.ruleForm.email);
      params.append("password", this.ruleForm.password);
      getLoginStatus(params).then((res) => {
        if (res.code === 1) {
          localStorage.setItem("email", this.ruleForm.email);
          this.$router.push("/index");
          this.notify("登录成功", "success");
        } else {
          this.notify("登录失败", "error");
        }
      });
    },
    registerForm() {
      this.$router.push("/register");
    },
    resetpwdForm() {
      this.$router.push("/resetpwd");
    },
    // userinformationForm() {
    //   this.$router.push("/userinformation")
    // },
    // indexForm() {
    //   this.$router.push("/index")
    // },
  },
};
</script>
<style scoped>
.login-wrap {
  width: 1024px;
  height: 600px;
  margin: 6% 0 0 20%;
  background-color: #fff;
}
.login-img {
  width: 350px;
  height: 200px;
  margin: 180px 0 0 80px;
}
.left-context {
  float: left;
  width: 512px;
  height: 600px;
  background-color: #9a9aeb;
}
.right-context {
  position: relative;
  float: right;
  width: 512px;
  height: 600px;
}
.context-text {
  text-align: center;
  font-size: 24px;
  font-weight: 600;
  margin-top: 80px;
}
.context-login {
  position: absolute;
  width: 350px;
  height: 250px;
  margin-left: 95px;
  margin-top: 40px;
}
.submit-btn {
  width: 100%;
  background-color: #1e1e1e;
  border-radius: 5px;
}
.forget-pwd {
  padding-left: 195px;
  color: #1e1e1e;
}
.jump-register {
  margin: 300px 0 0 190px;
  font-size: 14px;
}
</style>
